package com.lzb.play;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.lzb.play.databinding.ActivityHomeBinding;
import com.lzb.play.fragment.GestureSlideFragment;
import com.lzb.play.fragment.HomeFragment;
import com.lzb.play.fragment.PianoPlayFragment;
import com.lzb.play.fragment.RhythmGridFragment;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class HomeActivity extends BaseTabFragmentHomeActivity<ActivityHomeBinding> {

    @Override
    protected void initView() {
        super.initView();
        mDataBinding.llHomeBottom.setOnClickListener(null);
    }

    @NonNull
    @Override
    protected List<BaseTabFragmentHomeActivity<ActivityHomeBinding>.FragmentViewBinder> getFragmentViewBinders() {
        List<FragmentViewBinder> listFragment = new ArrayList<>();
        listFragment.add(new FragmentViewBinder(HomeFragment.class, R.id.llHome));
        listFragment.add(new FragmentViewBinder(PianoPlayFragment.class, R.id.llPianoPlay));
        listFragment.add(new FragmentViewBinder(GestureSlideFragment.class, R.id.llGestureSlide));
        listFragment.add(new FragmentViewBinder(RhythmGridFragment.class, R.id.llRhythmGrid));
        return listFragment;
    }

    @Override
    protected void onFragmentViewClick(View view) {
        clearSelection();
        int id = view.getId();
        if (id == R.id.llHome) {
            mDataBinding.ivHome.setImageResource(R.drawable.icon_index_on);
            mDataBinding.tvHome.setTextColor(Color.parseColor("#00A678"));
        } else if (id == R.id.llPianoPlay) {
            mDataBinding.ivPianoPlay.setImageResource(R.drawable.icon_piano_on);
            mDataBinding.tvPianoPlay.setTextColor(Color.parseColor("#00A678"));
        } else if (id == R.id.llGestureSlide) {
            mDataBinding.ivGestureSlide.setImageResource(R.drawable.icon_gesture_on);
            mDataBinding.tvGestureSlide.setTextColor(Color.parseColor("#00A678"));
        } else if (id == R.id.llRhythmGrid) {
            mDataBinding.ivRhythmGrid.setImageResource(R.drawable.icon_grid_on);
            mDataBinding.tvRhythmGrid.setTextColor(Color.parseColor("#00A678"));
        }
    }

    @Override
    protected int getFragmentContainerId() {
        return R.id.flContainer;
    }

    @Override
    protected int onCreate() {
        return R.layout.activity_home;
    }

    private void clearSelection() {
        mDataBinding.ivHome.setImageResource(R.drawable.icon_index_off);
        mDataBinding.tvHome.setTextColor(Color.parseColor("#9C9C9C"));
        mDataBinding.ivPianoPlay.setImageResource(R.drawable.icon_piano_off);
        mDataBinding.tvPianoPlay.setTextColor(Color.parseColor("#9C9C9C"));
        mDataBinding.ivGestureSlide.setImageResource(R.drawable.icon_gesture_off);
        mDataBinding.tvGestureSlide.setTextColor(Color.parseColor("#9C9C9C"));
        mDataBinding.ivRhythmGrid.setImageResource(R.drawable.icon_grid_off);
        mDataBinding.tvRhythmGrid.setTextColor(Color.parseColor("#9C9C9C"));
    }

}